//
//  AEPointsAcquireViewModel.m
//  AESOLAR_IOS
//
//  Created by Bin Tang on 2024/10/15.
//  Copyright © 2024 Mr.Wang. All rights reserved.
//

#import "AEPointsAcquireViewModel.h"

@implementation AEPointsAcquireViewModel

- (void)initialize {
    [super initialize];
    
    _signList = [NSMutableArray new];
    
}

- (void)setupData {
    
    /*
    TYZCommonCellModel *model = [TYZCommonCellModel new];
    model.title = @"第1天";
    model.value = @"10积分";
    model.isCheck = YES;
    [self.signList addObject:model];
    
    model = [TYZCommonCellModel new];
    model.title = @"第2天";
    model.value = @"惊喜好礼";
    model.isCheck = NO;
    [self.signList addObject:model];
    
    model = [TYZCommonCellModel new];
    model.title = @"第3天";
    model.value = @"15积分";
    model.isCheck = NO;
    [self.signList addObject:model];
    
    model = [TYZCommonCellModel new];
    model.title = @"第4天";
    model.value = @"10积分";
    model.isCheck = NO;
    [self.signList addObject:model];
    
    model = [TYZCommonCellModel new];
    model.title = @"第5天";
    model.value = @"20积分";
    model.isCheck = NO;
    [self.signList addObject:model];
    
    model = [TYZCommonCellModel new];
    model.title = @"第6天";
    model.value = @"8积分";
    model.isCheck = NO;
    [self.signList addObject:model];
    
    model = [TYZCommonCellModel new];
    model.title = @"第7天";
    model.value = @"双倍积分";
    model.isCheck = NO;
    [self.signList addObject:model];
    */
    
//    [self.dataList removeAllObjects];
}

- (void)parseTask:(AESignTaskModel *)taskModel {
    TYZCommonCellModel *model = [TYZCommonCellModel new];
    model.iconImgName = @"ic_person_info_cell";
    model.title = @"完善个人信息";
    model.value = @"10";
    model.index = 1;
    model.isCheck = [AEAppDelegateTool sharedInstance].userInfoModel.hasPerfect;
    [self.dataList addObject:model];
    
    model = [TYZCommonCellModel new];
    model.iconImgName = @"ic_post_review_cell";
    model.title = @"发布内容/评论（日常内容）";
    model.value = @"10";
    model.index = 2;
    model.isCheck = (taskModel.commentsTask > 0 ? YES : NO);
    [self.dataList addObject:model];
    
    model = [TYZCommonCellModel new];
    model.iconImgName = @"ic_browse_content_cell";
    model.title = @"浏览内容";
    model.value = @"10";
    model.index = 3;
    model.isCheck = (taskModel.browseTask > 0 ? YES : NO);
    [self.dataList addObject:model];
    
    model = [TYZCommonCellModel new];
    model.iconImgName = @"ic_association_cell";
    model.title = @"社群发布内容";
    model.value = @"10";
    model.index = 4;
    model.isCheck = (taskModel.newsTask > 0 ? YES : NO);
    [self.dataList addObject:model];
}

/// 获取任务
/// - Parameter completion: completion description
- (void)requestWithSignTasks:(RequestCompletionBlock)completion {
    @weakify(self);
    AESignTasksRequest *request = [[AESignTasksRequest alloc] init];
    [request startWithCompletionBlockWithSuccess:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        EDSRespondDataEntity *respond = request.responseModelObject;
        if (respond.code == EDS_NETWORK_SUCCESS) {
            self.taskModel = respond.data;
            [self parseTask:self.taskModel];
        }
        [self sendResponseObject:request.responseModelObject completion:completion];
    } failure:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        [self sendResponseObject:request.responseModelObject completion:completion];
    }];
}

/// 签到
/// - Parameter completion: completion description
- (void)requestWithSignIn:(RequestCompletionBlock)completion {
    @weakify(self);
    AESignInRequest *request = [[AESignInRequest alloc] init];
    [request startWithCompletionBlockWithSuccess:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        EDSRespondDataEntity *respond = request.responseModelObject;
        if (respond.code == EDS_NETWORK_SUCCESS) {
            // signedInfoModel
            if (self.signedInfoModel) {
                self.signedInfoModel.signCount += 1;
                for (int i=0; i<self.signList.count; i++) {
                    if ((i+1 <= self.signedInfoModel.signCount)) {
                        self.signList[i].isSign = YES;
                    }
                }
            }
        }
        [self sendResponseObject:request.responseModelObject completion:completion];
    } failure:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        [self sendResponseObject:request.responseModelObject completion:completion];
    }];
}

/// 获取签到内容
/// - Parameter completion: completion description
- (void)requestWithSignInfos:(RequestCompletionBlock)completion {
    @weakify(self);
    AESignInfosRequest *request = [[AESignInfosRequest alloc] init];
    [request startWithCompletionBlockWithSuccess:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        EDSRespondDataEntity *respond = request.responseModelObject;
        if (respond.code == EDS_NETWORK_SUCCESS) {
            [self.signList removeAllObjects];
            [self.signList addObjectsFromArray:respond.data];
            for (int i=0; i<self.signList.count; i++) {
                if ((i+1 <= self.signedInfoModel.signCount)) {
                    self.signList[i].isSign = YES;
                }
            }
        }
        [self sendResponseObject:request.responseModelObject completion:completion];
    } failure:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        [self sendResponseObject:request.responseModelObject completion:completion];
    }];
}

/// 获取签到情况
/// - Parameter completion: completion description
- (void)requestWithSignDatas:(RequestCompletionBlock)completion {
    @weakify(self);
    AESignDataInfoRequest *request = [[AESignDataInfoRequest alloc] init];
    [request startWithCompletionBlockWithSuccess:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        EDSRespondDataEntity *respond = request.responseModelObject;
        if (respond.code == EDS_NETWORK_SUCCESS) {
            self.signedInfoModel = respond.data;
        }
        [self sendResponseObject:request.responseModelObject completion:completion];
    } failure:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        [self sendResponseObject:request.responseModelObject completion:completion];
    }];
}

@end
